package com.aaa.springbootredis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@SpringBootTest
class SpringbootRedisApplicationTests2 {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Test
    public void test01(){
        //默认RedisTemplate它的key和value的序列化都是使用的JdkSerializationRedisSerializer方式，该序列化要求类必须实现Serializable接口。
//
//        redisTemplate.setKeySerializer(new StringRedisSerializer());
//        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("k2",new Student("张三",20,"中国"));
        System.out.println(valueOperations.get("k2"));
    }
    @Test
    public void test2(){
        HashOperations hashOperations=redisTemplate.opsForHash();
        hashOperations.put("k1","name","sss");
    }

}
